//
//  LYRequest.h
//  LYDevelopKit
//
//  Created by 李阳 on 2018/6/1.
//

#import "YTKRequest.h"

@class LYRequest;

typedef void(^LYRequestBlock)(LYRequest *request);

@interface LYRequest : YTKRequest

/// URL path of request.
@property (nonatomic, copy) NSString *urlPath;

/// Requset timeout interval. Default is 60s.
@property (nonatomic, assign) NSTimeInterval timeoutInterval;

/// HTTP request method.
@property (nonatomic, assign) YTKRequestMethod method;

/// Request serializer type.
@property (nonatomic, assign) YTKRequestSerializerType requestSerializerType;

/// Response serializer type.
@property (nonatomic, assign) YTKResponseSerializerType responseSerializerType;

/// Whether the request is allowed to use the cellular radio Default is YES.
@property (nonatomic, assign) BOOL allowsCellularAccess;

/// request argument.
@property (nonatomic, strong) id argument;

/// The validator will be used to test if `responseJSONObject` is correctly formed.
@property (nonatomic, strong) id jsonValidator;

/// 认为成功的返回码，除successCodeSet以外都认为失败
@property (nonatomic, strong) NSArray<NSNumber *> *successCodeSet;

/// 认为失败的返回码，除errorCodeSet以外都认为成功
@property (nonatomic, strong) NSArray<NSNumber *> *errorCodeSet;

- (void)addValue:(NSString *)value forHeaderField:(NSString *)field;
- (void)setAuthorizationWithUsername:(NSString *)username password:(NSString *)password;

///  The max time duration that cache can stay in disk until it's considered expired.
///  Default is -1, which means response is not actually saved as cache.
@property (nonatomic, assign) NSInteger cacheTimeInSeconds;

///  Version can be used to identify and invalidate local cache. Default is 0.
@property (nonatomic, assign) long long cacheVersion;


///  Called on background thread after request succeded but before switching to main thread. Note if
///  cache is loaded, this method WILL be called on the main thread, just like `requestCompleteFilter`.
@property (nonatomic, copy) LYRequestBlock completePreprocessor;

///  Called on the main thread after request succeeded.
@property (nonatomic, copy) LYRequestBlock completeFilter;

///  Called on background thread after request failed but before switching to main thread. See also
///  `requestCompletePreprocessor`.
@property (nonatomic, copy) LYRequestBlock failedPreprocessor;

///  Called on the main thread when request failed.
@property (nonatomic, copy) LYRequestBlock failedFilter;

@end

